package org.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.common.Result;
import org.example.controller.request.ProjectRequest;
import org.example.controller.request.ProjectReviewRequest;
import org.example.entity.Project;
import org.example.entity.ProjectReview;
import org.example.entity.Resources;
import org.example.entity.Review;
import org.example.service.ProjectReviewService;
import org.example.service.ProjectService;
import org.example.service.ResourceService;
import org.example.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/expert")
public class ExpertController {
    @Autowired
    private ProjectService projectService;
    @Autowired
    private ProjectReviewService projectReviewService;

    @GetMapping("/selectProject0")
    public Result selectProject0(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        Page<Project> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Project> wrapper = new QueryWrapper<Project>().eq("reviewer",TokenUtils.getCurrentUser().getName()).orderByAsc("id");

// 执行分页查询（同时包含分页参数和排序条件）
        projectService.page(page, wrapper);

        return Result.success(page);
    }

    @PostMapping("/review")
    public Result ProjectReview(@RequestBody ProjectReviewRequest projectReviewRequest){
        ProjectReview projectReview=new ProjectReview();
        projectReview.setInnovation(projectReviewRequest.getInnovation());
        projectReview.setFeasibility(projectReviewRequest.getFeasibility());
        projectReview.setMarketpotential(projectReviewRequest.getMarketPotential());
        projectReview.setUsername(projectReviewRequest.getUsername());
        projectReview.setProjectname(projectReviewRequest.getProjectname());
        projectReview.setComments(projectReviewRequest.getComments());


//        LocalDateTime now = LocalDateTime.now();
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        projectReview.setCreated_at(now.format(formatter));

        projectReviewService.save(projectReview);
        projectService.updatreview(projectReviewRequest.getProjectname());
        return Result.success();
    }
}
